<php>if(!$isLoadScript){</php>
<style>
.file_li{
	border:2px dashed #ddd;
	background:#fff;
	padding:8px;
	clear:both;
}
.clear{ clear:both;}
.file_li_trash{ float:right;}
</style>
<php>}</php>

<div id="file_list_{$id}" style="clear:both; display:block;">
    <empty name="file">
    <else/>
		<div class="file_li">{$file.name} <a onclick="remove_file_{$id}(this,{$file.id})" class="file_li_trash">删除</a></div>
    </empty>
    <div class="clear"></div>
</div>

<div id="uploader_{$id}" style="clear:both;margin-top:10px;">
	<input type="button" id="insertfile_{$id}" value="选择文件" />
</div>
<input name="{$name}" id="file_upload_{$id}" type="hidden" value="{$value}">
<script>
	layui.use('upload', function(){
		var upload = layui.upload;
		upload.render({
			url: '{:U("Home/File/uploadFile",array("session_id"=>session_id()))}'
			,elem: '#insertfile_{$id}' //指定原始元素，默认直接查找class="layui-upload-file"
			,method: 'post' //上传接口的http类型
			,accept: 'file'
			,field: '{$name}_id'
			,before: function(input){
				//layer.msg('文件上传中', {icon: 16, fixed: true, offset: '80%', time:2000});
				layer.load(2, {shade: false});
			}
			,done: function(res, index, upload){
				layer.closeAll('loading'); //关闭loading
				$("#file_list_{$id}").html('<div>'+ res.url.{$name}_id.name +' <a onclick="remove_file_{$id}'+'(this,'+ res.url.{$name}_id.id +')">删除</a></div>');
				$("[name='{$name}']").val(res.url.{$name}_id.id);
			}
			,error: function(index, upload){
				layer.closeAll('loading'); //关闭loading
				layer.msg(data.info, {icon: 2, fixed: true, offset: '80%', time:1000});
			}
		});
	});

    //$('#file_upload_{$id}').val(ret.data.file.id);
	function remove_file_{$id}(obj, attachId) {
        $('#file_upload_{$id}').val('');
        $(obj).parent('div').remove();
    }
</script>